package com.ejuornal.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Editor;
import com.ejuornal.bean.Page;
import com.ejuornal.dao.EditorDao;

@Component("editorDao")
public class EditorDaoImpl extends DaoSupport<Editor> implements EditorDao {
	public void add(String sql, Object... objs) {
		super.add(sql, objs);
	}

	public void update(String sql, Object... objs) {
		super.update(sql, objs);
	}

	public Editor findById(int userId) {
		String sql = "select *  from t_editor where userId=?";

		Editor editor = getJdbcTemplate().queryForObject(sql,
				new Object[] { userId }, new RowMapper<Editor>() {

					public Editor mapRow(ResultSet rs, int roeNum)
							throws SQLException {
						Editor editor = new Editor();
						editor.setEditorId(rs.getInt("editorId"));
						editor.setPeriodicalId(rs.getInt("periodicalId"));
						editor.setStatus(rs.getString("status"));
						editor.setUserId(rs.getInt("userId"));
						editor.setLeaveDate(rs.getDate("leaveDate"));
						editor.setWorkDate(rs.getDate("workDate"));

						return editor;
					}
				});

		return editor;
	}

	public List<Editor> findByPeriodicalId(int periodicalId) {
		String sql = "SELECT * FROM t_editor WHERE periodicalId=?";
		List<Editor> editorList = super.getJdbcTemplate().query(sql,
				new Object[] { periodicalId }, new RowMapper<Editor>() {

					public Editor mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						Editor editor = new Editor();
						editor.setEditorId(rs.getInt("editorId"));
						editor.setPeriodicalId(rs.getInt("periodicalId"));
						editor.setStatus(rs.getString("status"));
						editor.setUserId(rs.getInt("userId"));
						editor.setLeaveDate(rs.getDate("leaveDate"));
						editor.setWorkDate(rs.getDate("workDate"));

						return editor;
					}

				});

		return editorList;
	}

	public Page<Editor> findByProperty(String prop, Object value) {

		return null;
	}

	@Override
	public Page<Editor> findByProperty(int current_record, String url) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
